<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
    window.onresize=function(){
        var w=document.documentElement.clientWidth;
        if(w>0&&w<=320){
            document.body.style.backgroundColor="skyblue";
        }
        else if(w>320&&w<=640){
            document.body.style.backgroundColor="red";
        }
        else if(w>640&&w<=960){
            document.body.style.backgroundColor="yellow";
        }
        else if(w>960&&w<=1040){
            document.body.style.backgroundColor="green";
        }
        else{
            document.body.style.backgroundColor="blue";
        }
    }
    </script>
</body>
</html>